package 工厂模式.工厂方法模式.factory;

import 工厂模式.工厂方法模式.factory.impl.DiscountFreeGoodsFactory;
import 工厂模式.工厂方法模式.factory.impl.SmallGiftGoodsFactory;
import 工厂模式.工厂方法模式.factory.impl.YouKuMemberFreeGoodsFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂的工厂 用来创建工厂类的对象
 */
public class FreeGoodsFactoryMap {
    // 创建map 集合 保存工厂对象
    private static final Map<Integer, FreeGoodsFactory> cachedFactories = new HashMap<>();

    static {
        cachedFactories.put(1, new DiscountFreeGoodsFactory());
        cachedFactories.put(2, new SmallGiftGoodsFactory());
        cachedFactories.put(3, new YouKuMemberFreeGoodsFactory());
    }

    public static FreeGoodsFactory getParserFactory(Integer type){
        if (type == 1){
            return cachedFactories.get(type);
        } else if (type == 2) {
            return cachedFactories.get(type);
        } else if (type == 3) {
            return cachedFactories.get(type);
        }
        return null;
    }
}
